package de.wojenko.sps;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

public class JAXBUtils {
	public static <T> T unmarshall(Class<T> type, File source,
			Class<?>... types) throws JAXBException {
			JAXBContext jc = JAXBContext.newInstance(types);
			Unmarshaller unmarschaller = jc.createUnmarshaller();
			Object o = unmarschaller.unmarshal(source);
			return type.cast(o);
	}

	public static void marshall(Object obj, File sink, Class<?>... types) throws JAXBException {
		JAXBContext jc = JAXBContext.newInstance(types);
		Marshaller marshaller = jc.createMarshaller();
		marshaller.marshal(obj, sink);
	}
}
